﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using NBHF.Models;
using NBHF.BusinessService;
using System.Text;
using System.IO;
using System.Data.OleDb;

public partial class Frame_User : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
 
        if (!IsPostBack)
        {
            string strPageIndex = Request["PageIndex"] != null ? Request["PageIndex"].ToString() : "";


            if (!string.IsNullOrEmpty(strPageIndex))
            {
                this.hidPageIndex.Value = strPageIndex;
            }

            //DateTime dtnow = DateTime.Now;

            //DateTime start = new DateTime(dtnow.Year, dtnow.Month, 1, 0, 0, 0);
            //DateTime end = new DateTime(dtnow.AddDays(1).Year, dtnow.AddDays(1).Month, dtnow.AddDays(1).Day, 0, 0, 0);

            //if (Session["startdt"] != null)
            //{
            //    this.Webdatetimeedit1.Text = Session["startdt"].ToString();
            //}
            //else
            //{
            //    this.Webdatetimeedit1.Text = start.ToString("yyyy-MM-dd");
            //    Session["startdt"] = start.ToString("yyyy-MM-dd");
            //}

            //if (Session["enddt"] != null)
            //{
            //    this.Webdatetimeedit2.Text = Session["enddt"].ToString();
            //}
            //else
            //{
            //    this.Webdatetimeedit2.Text = end.ToString("yyyy-MM-dd");
            //    Session["enddt"] = end.ToString("yyyy-MM-dd");
            //}

            //this.txtBillnoQuery.Text = Session["txtBillnoQuery"] != null ? Session["txtBillnoQuery"].ToString() : "";

            //SystemOption sysOption = new SystemOption();
            hidPageCount.Value = "20";

            //this.GetData(); 
        }
    }



    /// <summary>
    /// 获取数据
    /// </summary>
    private void GetData()
    {
        //UserBL bl = new UserBL();

        //string roleref = "";
        //if (Session["UserQueryRoleref"] != null && !"0".Equals(Session["UserQueryRoleref"].ToString()))
        //{
        //    roleref = Session["UserQueryRoleref"].ToString();
        //}

        string billnoquery = this.txtBillnoQuery.Text.Trim();

        string start = this.Request.Form[this.Webdatetimeedit1.UniqueID].Trim();
        string end = this.Request.Form[this.Webdatetimeedit2.UniqueID].Trim();

        //string billnoquery = Session["txtBillnoQuery"] != null ? Session["txtBillnoQuery"].ToString() : "";

        //string start = Session["startdt"] != null ? Session["startdt"].ToString() : "";
        //string end = Session["enddt"] != null ? Session["enddt"].ToString() : "";
        string _cusref = Session[SessionType.Cusref] != null ? Session[SessionType.Cusref].ToString() : "";
        string _userid = Session[SessionType.Userid] != null ? Session[SessionType.Userid].ToString() : "";

        FindOnlineChangeBillForWebQueryResultModel result = IntergrationService.FindOnlineChangeBillForWebQuery(
            new FindOnlineChangeBillForWebQueryModel() { userid = _userid, billno = billnoquery, sdt = start, edt = end }
            );
        List<FindOnlineChangeBillForWebQueryResultDataModel> query = result.data;
        this.grdUser.DataSource = query;

        grdUser.PageSize = int.Parse(hidPageCount.Value);
        grdUser.PageIndex = int.Parse(this.hidPageIndex.Value);
        grdUser.DataBind();

        if (query == null || query.Count < 1)
        {
            lblDataCount.Text = "共有0条记录。";
        }
        else
        {


            int count = query.Count;
            lblDataCount.Text = "共有" + count.ToString() + "条记录。 箱数：" + result.plctns.ToString();
        }
    }

 

    /// <summary>
    /// 分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grdUser_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.grdUser.PageIndex = e.NewPageIndex;
        hidPageIndex.Value = e.NewPageIndex.ToString();
        this.GetData();
    }



    /// <summary>
    /// 刷新
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        //this.hidPageIndex.Value = "0";

        //DateTime dtnow = DateTime.Now;

        //DateTime start = new DateTime(dtnow.Year, dtnow.Month, 1, 0, 0, 0);
        //DateTime end = new DateTime(dtnow.AddDays(1).Year, dtnow.AddDays(1).Month, dtnow.AddDays(1).Day, 0, 0, 0);

        //Session["txtBillnoQuery"] = null;
        //Session["startdt"] = start.ToString("yyyy-MM-dd");
        //Session["enddt"] = end.ToString("yyyy-MM-dd");

        //this.txtBillnoQuery.Text = "";
        //this.Webdatetimeedit1.Text = start.ToString("yyyy-MM-dd");
        //this.Webdatetimeedit2.Text = end.ToString("yyyy-MM-dd");

        //this.GetData();
    }

    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnFind_Click1(object sender, EventArgs e)
    {
        //Session["txtBillnoQuery"] = this.txtBillnoQuery.Text.Trim();

        //string str1 = this.Request.Form[this.Webdatetimeedit1.UniqueID].Trim();
        //string str2 = this.Request.Form[this.Webdatetimeedit2.UniqueID].Trim();

        //Session["startdt"] =  Convert.ToDateTime(this.Request.Form[this.Webdatetimeedit1.UniqueID].Trim()).ToString("yyyy-MM-dd");
        //Session["enddt"] =  Convert.ToDateTime(this.Request.Form[this.Webdatetimeedit2.UniqueID].Trim()).ToString("yyyy-MM-dd");

        this.GetData();
    }
     



     
}